package com.bwie.controller;

import com.bwie.config.TouristInfo;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther:${涛}
 * @Date:2024/8/31 08:13
 * @Description: TouristController
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/team")
public class TouristController {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;


    @PostMapping("/save")
    public R save() {
        IndexOperations indexOperations = elasticsearchRestTemplate.indexOps(TouristInfo.class);

        boolean exists = indexOperations.exists();

        if (exists) {
            indexOperations.delete();
        }

        indexOperations.create();

        Document mapping = indexOperations.createMapping();
        indexOperations.putMapping(mapping);
        return R.OK("创建成功");
    }
}


